package com.leizhi.demo.monitor.controller;

import com.leizhi.demo.monitor.pojo.SrsCallbackDto;
import com.leizhi.demo.monitor.pojo.SrsCallbackDvrDto;
import com.leizhi.demo.monitor.service.SrsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description SRS 控制器（该类是给 SRS 服务器调用的）
 * @Version 1.0.0-SNAPSHOT
 * @Author leizhi
 * @Date 2025/4/29 16:07
 */
@RestController
@RequestMapping("/srs")
public class SrsController {

    private static final Logger logger = LoggerFactory.getLogger(SrsController.class);

    @Autowired
    private SrsService srsService;


    @PostMapping("/play")
    public Integer play(@RequestBody SrsCallbackDto dto) {
        try {
            srsService.onPlay(dto);
            return 0;    // 这里是因为 SRS 的返回成功值是 0
        } catch (Exception e) {
            logger.error("SRS 服务器回调失败", e);
            return 500;
        }
    }

    @PostMapping("/stop")
    public Integer stop(@RequestBody SrsCallbackDto dto) {
        try {
            srsService.onStop(dto);
            return 0;    // 这里是因为 SRS 的返回成功值是 0
        } catch (Exception e) {
            logger.error("SRS 服务器回调失败", e);
            return 500;
        }
    }

    @PostMapping("/dvr")
    public Integer dvr(@RequestBody SrsCallbackDvrDto dto) {
        try {
            srsService.dvr(dto);
            return 0;    // 这里是因为 SRS 的返回成功值是 0
        } catch (Exception e) {
            logger.error("SRS 服务器回调失败", e);
            return 500;
        }
    }

}
